import {ComponentType} from 'react'
import Taro, {Component, Config} from '@tarojs/taro'
import {View, Button, Text, Swiper, SwiperItem, Image, ScrollView, Form, Input, Picker} from '@tarojs/components'
import {getAvatar, pageSize, subTime, setStorage, navigateTo, memberTypeArr} from "../../utils/common";

import {inject, observer} from '@tarojs/mobx'
import {IStoreProps} from '../../store/Stores'

import './authed.scss'


interface IHomeProps extends IStoreProps {
}

@inject("stores")
@observer
class Authed extends Component<IHomeProps> {
  constructor(props) {
    super(props)
  }

  state = {}

  componentWillMount() {
    // this.getSpreadUsers()
    // this.getUserShareCount()
    // this.getAllPrivilegeTypes()
  }

  getUserShareCount(): void {
    let {userStore} = this.props.stores
    userStore.getUserShareCount({
      callback: res => {
        this.setState({shareCount: res})
      }
    })
  }

  getSpreadUsers() {
    let {userStore} = this.props.stores
    let {currentNavId, pageIndex, pageSize} = this.state
    userStore.getSpreadUsers({
      formPrivilegeId: currentNavId,
      pageIndex,
      pageSize,
      callback: res => {
        if (pageIndex === 1) {
          this.setState({totalCount: res.totalCount, items: res.items})
        } else {
          const {items} = this.state;
          items.push(...res.items || []);
          this.setState({totalCount: res.totalCount, items})
        }
      }
    })
  }

  onReachBottom(): void {
    let {totalCount, pageSize, pageIndex} = this.state
    const {loading} = this.props.stores.homeStore;
    if (totalCount > pageIndex * pageSize && !loading) {
      this.setState({
        pageIndex: pageIndex + 1
      }, () => {
        this.getSpreadUsers()
      })
    }
  }

  changeCurrentNavId(id: number) {
    this.setState({
      currentNavId: id,
      pageIndex: 1,
      items: [],
    }, () => {
      this.getSpreadUsers()
    })
  }

  teamMember(item: object) {
    // 缓存信息给下个页面使用
    setStorage('fatherUser', item)
    navigateTo('/pages/user/team_member?id=' + item.id)
  }

  // 获取特权列表
  getAllPrivilegeTypes() {
    let {homeStore} = this.props.stores
    homeStore.getAllPrivilegeTypes({
      callback: res => {
        this.setState({
          vipList: res.items
        })
      }
    })
  }

  link(url: string = '/pages/index/index'): void {
    navigateTo(url)
  }

  submit() {
  }

  changePicker() {
  }

  render() {
    return (
      <View className='page-bg content-20'>
        <View className='line-common__wrap'>
          <View className='line-common'>
            <View className='line-common__title'>姓名</View>
            <View className='line-common__desc'>99</View>
          </View>
          <View className='line-common'>
            <View className='line-common__title'>身份证号</View>
            <View className='line-common__desc'>已认证</View>
          </View>
          <View className='line-common'>
            <View className='line-common__title'>认证时间</View>
            <View className='line-common__desc'>未认证</View>
          </View>
          <View className='line-common'>
            <View className='line-common__title'>认证结果</View>
            <View className='line-common__desc color-theme'>审核通过</View>
          </View>
        </View>
      </View>
    )
  }
}

export default Authed

